package com.anorak.betsy.shell;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.RuntimeUtil;
import cn.hutool.core.util.ZipUtil;
import com.strobel.decompiler.Decompiler;
import com.strobel.decompiler.DecompilerSettings;
import com.strobel.decompiler.PlainTextOutput;

import java.io.File;
import java.io.FileOutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.jar.JarFile;

public class Run {

    // 大量的 DEX dex 处理 反编译为.class 汇总结构
    public static void main(String[] args) {
        String jarPath = "/Users/anorak/Documents/android_code/cfr-0.152.jar";
        String directoryPath = "/Users/anorak/Documents/android_code/androidcode/infos";
        String outputDirectory = "/Users/anorak/Documents/android_code/androidcode/jar2";

//        File[] files = FileUtil.ls(directoryPath);
//        for (File file : files) {
//            if (file.getAbsolutePath().endsWith(".dex")){
//                String command = "d2j-dex2jar.sh " + file.getAbsolutePath();
//                String result = RuntimeUtil.execForStr(command);
//                System.out.println(result);
//            }
//        }

        File[] filesJar = FileUtil.ls(directoryPath);
        for (File file : filesJar) {
            if (file.getAbsolutePath().endsWith(".jar")) {
                String command = "java -jar " + jarPath + " " + file.getAbsolutePath() + " --outputdir " + outputDirectory;
                String result = RuntimeUtil.execForStr(command);
                System.out.println(file.getAbsolutePath() + "处理完成");
            }
        }
    }

}
